package com.projetTDA.tournoi_encours;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageButton;
import android.widget.TextView;

import com.projetTDA.R;
import com.projetTDA.metier.Match;

public class MyArrayAdapter extends ArrayAdapter<Match>
{
	Context context;
	ArrayList<Match> values;
	TextView textViewScore1;
	TextView textViewScore2;
	
	public MyArrayAdapter(Context context, ArrayList<Match> values)
	{
	    super(context, R.layout.tournois_encours_match_rowlayout, values);
	    this.context = context;
	    this.values = values;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent)
	{
		
		LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View rowView = inflater.inflate(R.layout.tournois_encours_match_rowlayout, parent, false);

		TextView textViewEquipe1 = (TextView) rowView.findViewById(R.id.equipe1);
		TextView textViewEquipe2 = (TextView) rowView.findViewById(R.id.equipe2);
		textViewScore1 = (TextView) rowView.findViewById(R.id.score1);
		textViewScore2 = (TextView) rowView.findViewById(R.id.score2);
		ImageButton imageButtonValider = (ImageButton) rowView.findViewById(R.id.valider);
		ImageButton imageButtonMoinsGauche = (ImageButton) rowView.findViewById(R.id.iconeMoins_Gauche);
		ImageButton imageButtonMoinsDroite = (ImageButton) rowView.findViewById(R.id.iconeMoins_Droite);
		ImageButton imageButtonPlusGauche = (ImageButton) rowView.findViewById(R.id.iconePlus_Gauche);
		ImageButton imageButtonPlusDroite = (ImageButton) rowView.findViewById(R.id.iconePlus_Droite);

		if(values.get(position).getScore2() != null || values.get(position).getScore2() != null)
		{
			imageButtonValider.setVisibility(View.INVISIBLE);
			imageButtonMoinsGauche.setVisibility(View.INVISIBLE);
			imageButtonMoinsDroite.setVisibility(View.INVISIBLE);
			imageButtonPlusGauche.setVisibility(View.INVISIBLE);
			imageButtonPlusDroite.setVisibility(View.INVISIBLE);
		}

		textViewEquipe1.setText(values.get(position).getEquipe1().getNom_equipe());
		textViewEquipe2.setText(values.get(position).getEquipe2().getNom_equipe());

		int score1 = values.get(position).getScore1() == null ? 0 : values.get(position).getScore1().intValue();
		int score2 = values.get(position).getScore2() == null ? 0 : values.get(position).getScore2().intValue();
		textViewScore1.setText(String.valueOf(score1));
		textViewScore2.setText(String.valueOf(score2));

		return rowView;
	}
}
